package com.cheng.example.atguigu.view2.client27;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;


/**
 * lock方式的可重入锁演示
 */
public class Test02 {
    Lock lock = new ReentrantLock();

    public  void f1() {
        lock.lock();
        try {
            System.out.println(Thread.currentThread().getName()+"\t"+"f1");
            f2();
        }finally {
            lock.unlock();
        }
    }

    public  void f2() {
        lock.lock();
        try {
            System.out.println(Thread.currentThread().getName()+"\t"+"f2");
        }finally {
            lock.unlock();
        }
    }

    public static void main(String[] args) {
        Test02 test02 = new Test02();

        new Thread(()->{
            test02.f1();
        },"t1").start();

        new Thread(()->{
            test02.f1();
        },"t2").start();

    }
}
